<?php

namespace App\Console\Commands\Fee;

use App\Enums\Fee\FeeEnum;
use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Enums\OpenShop\MissionTemplateEnum;
use App\Models\Fee\FeeAnnualOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\StartBusiness\OpenShopStartBusinessModel;
use App\Remote\Rms\RmsShopRemote;
use App\Service\OpenShop\Feishu\MissionTemplateService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class CheckContractBusiness extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fee:check-contract-business';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '检查所有门店的合同和开店时间';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        OpenShopSignOrderModel::query()
                              ->with('contractRel', 'startBusinessRel', 'progressRel')
                              ->where('step', '>=', SignOrderEnum::STEP_5)
                              ->where('status', '!=', SignOrderEnum::ORDER_STATUS_NO)
                              ->get()
                              ->each(function ($item) {
                                  if (!$item->progressRel) {
                                      return;
                                  }

                                  if (!$item->contractRel) {
                                      $this->info("shopCode:{$item->shopCode} 没有合同");
                                  }

                                  if ($item->progressRel->nowStepStatus == MissionTemplateEnum::STEP_STATUS_999) {
                                      if (!$item->startBusinessRel) {
                                          $this->info("shopCode:{$item->shopCode} 没有开业报告");
                                      }

                                      if (!$item->startBusinessRel->startBusinessTime) {
                                          $this->info("shopCode:{$item->shopCode} 没有开业日期");
                                      }
                                  }
                              });
    }

}
